package com.itheima.health.utils.sms;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.boot.SpringApplication;

/**
 * 短信发送工具类
 */
public class SmsUtils {
    public static final String VALIDATE_CODE = "SMS_205455476";//发送短信验证码
    public static final String ORDER_NOTICE = "SMS_192571486";//体检预约成功通知

    /**
     * 发送短信验证码
     *
     * @param phoneNumbers
     * @param param
     * @throws ClientException
     */
    public static void validUserTelephone(String phoneNumbers, String param)  {
        try {
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GBq9ZdaMTBpCVgDRLUN", "Qj3BCy0fl6adEqcrMqOYc66mJNI3mv");
            IAcsClient client = new DefaultAcsClient(profile);

            CommonRequest request = new CommonRequest();
            request.setSysMethod(MethodType.POST);
            request.setSysDomain("dysmsapi.aliyuncs.com");
            request.setSysVersion("2017-05-25");
            request.setSysAction("SendSms");
            request.putQueryParameter("RegionId", "cn-hangzhou");
            request.putQueryParameter("PhoneNumbers", phoneNumbers);
            request.putQueryParameter("SignName", "行走的菠菜");
            request.putQueryParameter("TemplateCode", VALIDATE_CODE);
            request.putQueryParameter("TemplateParam", "{\"code\":\"" + param + "\"}");

            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void orderSuccessMessage(String phoneNumbers, String param) {
        try {
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GBq9ZdaMTBpCVgDRLUN", "Qj3BCy0fl6adEqcrMqOYc66mJNI3mv");
            IAcsClient client = new DefaultAcsClient(profile);

            CommonRequest request = new CommonRequest();
            request.setSysMethod(MethodType.POST);
            request.setSysDomain("dysmsapi.aliyuncs.com");
            request.setSysVersion("2017-05-25");
            request.setSysAction("SendSms");
            request.putQueryParameter("RegionId", "cn-hangzhou");
            request.putQueryParameter("PhoneNumbers", phoneNumbers);
            request.putQueryParameter("SignName", "行走的菠菜");
            request.putQueryParameter("TemplateCode", VALIDATE_CODE);
            request.putQueryParameter("TemplateParam", "{\"code\":\"" + param + "\"}");

            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //1234
    public static void main(String[] args) throws ClientException {
        validUserTelephone("13971007912", "2345");
    }
}
